home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 22 code / PCI Driver Sample / NCR_DriverProject / Src / DriverDebugSupport.c next >
Encoding:
C/C++ Source or Header  |  1995-04-08  |  3.1 KB  |  123 lines  |  [TEXT/MPCC]

  1. /*                                DriverDebugSupport.c                                */
  2. /*
  3.  * DriverDebugSupport.c
  4.  * Copyright © 1994 Apple Computer Inc. All rights reserved.
  5.  */
  6. /*    .___________________________________________________________________________________.
  7.       | These routines are marginally useful. They were thrown together and should be        |
  8.       | redone for a production system. As debugging progressed, I relied more and more    |
  9.       | on looking at logging information. Crashing into MacsBug at any error is really    |
  10.       | only useful for the initial stages of development.                                |
  11.       |                                                                                    |
  12.       | Most of this file is compiled only if USE_LOG_LIBRARY is non-zero.                |
  13.     .___________________________________________________________________________________.
  14. */
  15. #include "NCRDriverPrivate.h"
  16.  
  17. #if USE_LOG_LIBRARY
  18. /*
  19.  * We don't trace these.
  20.  */
  21. void
  22. CheckStatus(
  23.         OSErr                    value,
  24.         ConstStr255Param        message
  25.     )
  26. {
  27.         if (value != noErr)
  28.             LogStatusString(value, message);
  29. }
  30.  
  31. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  32.  * Logging subroutines
  33.  */
  34. void                        LogMemory(
  35.         register void            *areaAddress,
  36.         register Size            byteCount
  37.     )
  38. {
  39.         unsigned long            startIndex;
  40.         unsigned long            endIndex;
  41.         unsigned long            i;
  42.         Str255                    work;
  43.  
  44.         /*
  45.          * WriteLogEntry writes up to 40 characters. This is organized as
  46.          *    Start Index                3
  47.          *    4 groups of 4 bytes:    4 * (8 + 1)
  48.          *    One left over for good luck.
  49.          */
  50.         WriteLogEntry(GLOBAL.logRecordPtr, 'LMem',
  51.             LogFormat3(kLogFormatAddress, kLogFormatUnsigned, kLogFormatString),
  52.             (unsigned long) areaAddress, byteCount, "\pLog Memory"
  53.         );
  54.         if (byteCount > 64)
  55.             byteCount = 64;
  56.         for (startIndex = 0; startIndex < byteCount; startIndex += 16) {
  57.             endIndex = startIndex + 16;
  58.             if (endIndex > byteCount)
  59.                 endIndex = byteCount;
  60.             work[0] = 0;
  61.             AppendHexLeadingZeros(work, startIndex, 3);
  62.             for (i = startIndex; i < endIndex; i++) {
  63.                 if ((i & 0x03) == 0x00)
  64.                     AppendChar(work, ' ');    
  65.                 AppendHexLeadingZeros(work, ((UInt8 *) areaAddress)[i], 2);
  66.             }
  67.             WriteLogEntry(GLOBAL.logRecordPtr, 'LMem', LogStringFormat, work);
  68.         }
  69. }
  70.  
  71. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  72.  * Output a string of hex digits with leading zeros. May not move memory. Note that
  73.  * "digits" is the field width, not the number of hex bytes. Debug only.
  74.  */
  75. void
  76. AppendHexLeadingZeros(
  77.         StringPtr                result,
  78.         unsigned long            value,
  79.         short                    fieldWidth
  80.     )
  81. {
  82.         if (--fieldWidth > 0)
  83.             AppendHexLeadingZeros(result, value >> 4, fieldWidth);
  84.         value &= 0x0F;
  85.         AppendChar(result,
  86.                 (value < 10)
  87.                 ? value + '0'
  88.                 : (value + ('A' - 10))
  89.             );
  90. }
  91.  
  92.  
  93. void
  94. AppendUnsigned(
  95.         StringPtr                result,
  96.         unsigned long            value
  97.     )
  98. {
  99.         if (value >= 10)
  100.             AppendUnsigned(result, value / 10);
  101.         AppendChar(result, (value % 10) + '0');
  102. }
  103.  
  104. #endif /* LOG_LIBRARY */
  105.  
  106. /*
  107.  * This is always present - it's needed for PublishInitFailureMsg.c
  108.  */
  109. void
  110. AppendSigned(
  111.         StringPtr                result,
  112.         signed long                value
  113.     )
  114. {
  115.         if (value < 0) {
  116.             AppendChar(result, '-');
  117.             value = (-value);
  118.         }
  119.         AppendUnsigned(result, (unsigned long) value);
  120. }
  121.  
  122.  
  123.